import 'package:cunyutech_flutter_core/cunyutech_flutter_core.dart';
import 'package:flutter/material.dart';

mixin LoadingMixin <T extends StatefulWidget> on State<T> {
  Map<String, bool> _loadingMap = {};

  bool getLoading(String key) {
    return _loadingMap[key];
  }

  wrapLoading(String key, FutureCallbackFunction call) {
    return () async {
      if(_loadingMap[key] == true) return;
      setState(() {
        _loadingMap[key] = true;
      });
      await call();
      setState(() {
        _loadingMap[key] = false;
      });
    };
  }
}